//
//  UserDetaileTableViewController.m
//  projectOfTeamSample
//
//  Created by lanou3g on 15/11/18.
//  Copyright © 2015年 liukai. All rights reserved.
//

#import "UserDetaileTableViewController.h"
#import "UserDetaileTableViewCell.h"
#import "loginViewController.h"
#import "RegisterViewController.h"
#import "SetTableViewController.h"
#import "ChatListController.h"
//#import <AVObject.h>
#import <AVUser.h>
@interface UserDetaileTableViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) UserDetaileTableViewCell *userCell;
@property (nonatomic,strong) AVUser *current;
@end

@implementation UserDetaileTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    [self.tableView registerClass:[UserDetaileTableViewCell class] forCellReuseIdentifier:@"cell"];
//    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
//    self.tableView.separatorColor = [UIColor cyanColor];
   self.current = [AVUser currentUser];
    if (self.current != nil)
    {
      self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"退出" style:(UIBarButtonItemStyleDone) target:self action:@selector(didClickRejectButton:)];
    }
}

// 点击退出的方法
-(void)didClickRejectButton:(UIBarButtonItem *)send{
    if (self.current) {
        send.title = @"";
        [self.tableView reloadData];
    }
     [AVUser logOut];
    self.current = [AVUser currentUser];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//
//    return 2;
//}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //#warning Incomplete implementation, return the number of rows
    return 6;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    self.userCell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    self.userCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
    NSArray *arr= @[@"登录/注册",@"管理我的糗事",@"我的糗友",@"调节亮度",@"静音",@"设置"];
    NSMutableArray *array = [NSMutableArray arrayWithArray:arr];
    NSArray *imagearray = @[@"yh",@"gl",@"ql",@"ld",@"jy",@"sz"];
    
        if (self.current != nil) {
            array[0] = @"已登录";
        }else{
             array[0] = @"登录/注册";
        }
 
        [self.userCell userDetaileCellLayoutWithArray:array imagearray:imagearray index:indexPath.row];
        return self.userCell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        
        if (self.current == nil) {
        loginViewController *loginvc = [[loginViewController alloc]init];
        [self.navigationController pushViewController:loginvc animated:YES];
        }else{
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"已经登录了哦" message:nil preferredStyle:(UIAlertControllerStyleActionSheet)];
            UIAlertAction * action = [UIAlertAction actionWithTitle:@"点我" style:(UIAlertActionStyleDefault) handler:nil];
            [alert addAction:action];
            [self presentViewController:alert animated:YES completion:nil];
        }
    }
    
    if (indexPath.row == 1) {
        if (self.current != nil) {
            
        }
    }
    
    if (indexPath.row == 2) {
        if (self.current != nil) {
            [self.navigationController pushViewController:[[ChatListController alloc]init] animated:YES];
        }
    }
    
    if (indexPath.row == 5) {
        if (self.current !=nil) {
                    [self.navigationController pushViewController:[[SetTableViewController alloc]init] animated:YES];
        }

    }
    
    
}

/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */

/*
 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 // Delete the row from the data source
 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
 } else if (editingStyle == UITableViewCellEditingStyleInsert) {
 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 }
 }
 */

/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
